import axios from '@/axios'

// 发送消息
export function sendMessage(data) {
  return axios({
    url: '/chat-im/message',
    method: 'post',
    data,
  })
}

// 取消固定消息
export function unfixedMessagePin(msgId) {
  return axios({
    url: `/chat-im/message/${msgId}/unpin`,
    method: 'post',
  })
}

// 查询撤回消息配置
export function getMsgRecallConfig(){
  return axios({
    url: `/chat-im/message/recall/config`,
    method: 'get'
  })
}

// 表情回复
export function emojiReply(data) {
  return axios({
    url: '/chat-im/msgReaction',
    method: 'post',
    data,
  })
}

// 固定消息
export function fixedMessagePin(msgId) {
  return axios({
    url: `/chat-im/message/${msgId}/pin`,
    method: 'post',
  })
}

// 标记消息
export function markTagMsg(id) {
  return axios({
    url: '/chat-im/message/' + id + '/markTag',
    method: 'post',
  })
}

// 频道成员删除消息
export function deleteMemberMsg(id) {
  return axios({
    url: '/chat-im/message/deleteMemberMsg/' + id,
    method: 'post',
    data: [],
  })
}

// 置顶消息
export function markTopMessage(id) {
  return axios({
    url: '/chat-im/message/' + id + '/markTop',
    method: 'post',
  })
}

// 置顶消息
export function markUnTopMessage(id) {
  return axios({
    url: '/chat-im/message/' + id + '/markUnTop',
    method: 'post',
  })
}

// 收藏消息
export function collectMessage(msgId) {
  return axios({
    url: `/chat-im/msg/favorite/add/${msgId}`,
    method: 'post',
  })
}

// 获取频道内@我的消息列表
export function getMentionMeList(params) {
  return axios({
    url: `/chat-im/message/mentionMe`,
    method: 'get',
    params,
  })
}

// 表情回复删除
export function emojiReplyDel(id) {
  return axios({
    url: '/chat-im/msgReaction/' + id,
    method: 'delete',
  })
}

// 添加消息标签
export function addMsgTextTag(msgId, data) {
  return axios({
    url: `/chat-im/message/${msgId}/addTextTag`,
    method: 'post',
    data,
  })
}

// 删除消息标签
export function deleteMsgTextTag(msgId, data) {
  return axios({
    url: `/chat-im/message/${msgId}/deleteTextTag`,
    method: 'post',
    data,
  })
}

// 取消标记消息
export function unmarkTagMsg(id) {
  return axios({
    url: '/chat-im/message/' + id + '/unmarkTag',
    method: 'post',
  })
}

// 查询收藏列表
export function getCollectList(params) {
  return axios({
    url: '/chat-im/msg/favorite/list',
    method: 'get',
    params,
  })
}

// 取消收藏消息
export function unCollectMessage(favoriteId) {
  return axios({
    url: `/chat-im/msg/favorite/delete/${favoriteId}`,
    method: 'post',
  })
}

// 查询固定消息列表
export function getPinMessageList(params) {
  return axios({
    url: '/chat-im/message/pinned/list',
    method: 'get',
    params,
  })
}

// 查询消息列表
export function getMessageList(params) {
  return axios({
    url: '/chat-im/message/list/channel',
    method: 'get',
    params,
  })
}

// 撤回消息
export function deleteMessage(id) {
  return axios({
    url: '/chat-im/message/' + id,
    method: 'delete',
  })
}

// 上传消息文件
export function uploadMsgFile(data, onUploadProgress) {
  return axios({
    url: '/chat-im/msgFile',
    method: 'post',
    data,
    timeout: 600000,
    onUploadProgress
  })
}

// 获取消息文件URL
export function getMsgFileURL(fileId, type, onDownloadProgress) {
  return axios({
    url: `/chat-im/msgFile/${fileId}/${type}`,
    method: 'get',
    responseType: 'arraybuffer',
    timeout: 600000,
    onDownloadProgress
  })
}

// 转发消息
export function forwardMessage(data) {
  return axios({
    url: '/chat-im/message/forward',
    method: 'post',
    data,
  })
}

// 预览图片
export function previewImg(fileId) {
  return axios({
    url: '/chat-im/msgFile/' + fileId + '/preview',
    method: 'get',
    responseType: 'blob',
  })
}

/**
 * 检查消息文件是否上传成功
 * @param uuid {string} 上传文件之前会给每个文件生成 uuid,用来对应上传成功后的推送文件数据
 */
export function inspectClientFile(uuid) {
  return axios({
    url: '/chat-im/msgFile/checkClientFile/' + uuid,
    method: 'get',
  })
}
